package com.yupi.project.service.impl;

import com.yupi.project.service.IntegralService;
import com.yupi.project.service.UserService;
import com.yupi.yuapicommon.model.common.BusinessException;
import com.yupi.yuapicommon.model.common.ErrorCode;
import com.yupi.yuapicommon.model.entity.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * 积分服务实现类
 *
 * @author yupi
 */
@Service
@Slf4j
public class IntegralServiceImpl implements IntegralService {

    @Resource
    private UserService userService;

    @Override
    public boolean getWool(Long woolCount, long userId) {
        User user = userService.getById(userId);
        if (user == null) {
            log.error("用户不存在");
            throw new BusinessException(ErrorCode.NOT_FOUND_ERROR, "用户不存在");
        }
        user.setWoolLeft(user.getWoolLeft() + woolCount);
        return userService.updateById(user);
    }
}




